<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="java.text.*"%>
<%@ page import="org.osee.administration.service.*"%>
<%@ page import="org.osee.administration.domain.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/html; charset=utf8" http-equiv="Content-Type" />
<title>OSee观点搜索引擎 - 广告管理</title>
<link rel="stylesheet" href="admin/styles/style.css" type="text/css" />
<script type="text/javascript" src="admin/script/ad.js"></script>
</head>
<body>
<%
	int currentPage = (Integer) request.getAttribute("currentPage");
	int totalPages = (Integer) request.getAttribute("totalPages");
	List<Advertisement> adList = null;
	try {
		adList = (List<Advertisement>) request.getAttribute("adList");
	} catch (Exception e) {
		e.printStackTrace();
	} finally {
		if (adList == null) {
			adList = new ArrayList<Advertisement>();
		}
	}

	DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
%>
<div id="container">
  <%@ include file="inc/header.inc"%>
  <div class="clr"></div>
  <%@ include file="inc/menu.inc"%>
  <div id="admin_content">
    <div id="banner">
      <div class="banner-c1"></div>
      <div class="banner-text">广告管理</div>
      <div class="banner-c2"></div>
    </div>
    <!-- siderbar   start -->
    <div id="new_ad" class="new_sth">
      <div class="ad-left-top">
        <div class="bar1-left"></div>
        <div class="bar1-right"></div>
      </div>
      <div id="siderContent">
        <ul>
          <li><span onclick="showAddAd()" style="cursor: pointer">添加广告</span>
            <ul id="addAd"
		style="border: #999999 1px solid; margin-top: 5px; margin-right: 10px; display: none; margin-bottom: 10px; cursor: text">
              <div
			style="padding-top: 5px; padding-right: 5px; cursor: pointer; float: right; width: 50px; height: 22px; font-size: 11px; text-align: right"
			onclick="addMultiAds()">多行添加</div>
              <form action="admin-addAd.htm" method="post">
                <li style="text-align: left; margin-left: 3px;">请输入广告名:</li>
                <li style="text-align: left; padding-left: 25px;">
                  <textarea
			style="height: 40px; width: 150px" name="adName"></textarea>
                </li>
                <li style="text-align: left; margin-left: 3px;">请输入广告链接:</li>
                <li style="text-align: left; padding-left: 25px;">
                  <input
			type="text" name="adHref" value="" style="width: 150px" />
                </li>
                <li style="margin-bottom: 5px;">
                  <input type="submit" value="提交"
			style="font-size: smaller" />
                </li>
              </form>
            </ul>
          </li>
          <li><span onclick="showSearchAd()" style="cursor: pointer">搜索广告</span>
            <ul id="searchAD"
		style="border: #999999 1px solid; margin-top: 5px; margin-right: 10px; display: none; margin-bottom: 10px">
              <form action="admin-searchAds.htm" method="post">
                <li>请输入关键字:</li>
                <li>
                  <input type="text" name="keyword" value="" />
                </li>
                <li style="margin-bottom: 5px;">
                  <input type="submit" value="提交"
			style="font-size: smaller" />
                </li>
              </form>
            </ul>
          </li>
          <li><span style="cursor: pointer"><a href="admin-ad.htm">查看广告</a></span></li>
        </ul>
      </div>
    </div>
    <!-- siderbar   end -->
    <!-- formList start -->
    <div id="admin_ctt_list">
      <div class="ad-right-top">
        <div class="bar2-left"></div>
        <div class="bar2-center"></div>
        <div class="bar2-right"></div>
      </div>
      <div id="formContent">
        <form action="" method="post">
          <div id="list">
            <div id="navigation"></div>
            <ul>
              <%
		for (Advertisement ad : adList) {
	%>
              <li id="<%=ad.getId()%>" onmouseover="showIcon(this)"
		onmouseout="hideIcon(this)"><span class="number"><%=ad.getId()%></span><span
		class="ad-name"><a href="<%=ad.getHref() %>" title="<%=ad.getName()%>" target="_blank">
                <%
		if (ad.getName().length() < 11) {
			out.println(ad.getName());
		} else {
			out.println(ad.getName().substring(0, 10) + "...");
		}
	%>
                </a></span><span class="ad-href"><a title="<%=ad.getHref()%>">
                <%
		if (ad.getHref().length() < 25) {
			out.println(ad.getHref());
		} else {
			out.println(ad.getHref().substring(0, 24) + "...");
		}
	%>
                </a></span><span
		class="ad-datetime"><%=dateFormat.format(ad.getDatetime())%></span><span
		class="edit" onclick="showEdit(<%=ad.getId() %>)">编辑</span><span class="delete"
		onclick="deleteAdById(<%=ad.getId() %>)">删除</span></li>
              <%
		}
	%>
            </ul>
            <div id="fenye"> <a href="admin-ad.htm?page=1">&laquo;</a>
              <%
	if(totalPages <= 7){
		for(int i = 1; i <= totalPages; i++){
			out.println("<a href=\"admin-ad.htm?page=" + i + "\">" + i + "</a>");
		}
	} else {
		if((currentPage - 1) > 3){
			out.println("<a href=\"admin-ad.htm?page=1\">1</a>&nbsp;...");
			out.println("<a href=\"admin-ad.htm?page=" + (currentPage - 1) +"\">" + (currentPage - 1) + "</a>");
			out.println("<a href=\"admin-ad.htm?page=" + (currentPage) +"\">" + (currentPage) + "</a>");
		} else {
			for(int i = 1; i < currentPage + 1; i++){
				out.println("<a href=\"admin-ad.htm?page=" + i + "\">" + i + "</a>");
			}
		}
		
		if((totalPages - currentPage) > 3 ){
			out.println("<a href=\"admin-ad.htm?page=" + (currentPage + 1) +"\">" + (currentPage + 1) + "</a>&nbsp;...");
			out.println("<a href=\"admin-ad.htm?page=" + (totalPages) +"\">" + (totalPages) + "</a>");
		}else {
			for(int i = currentPage + 1; i <= totalPages; i++){
				out.println("<a href=\"admin-ad.htm?page=" + i + "\">" + i + "</a>");
			}
		}
	}
%>
              <a href="admin-ad.htm?page=<%=totalPages %>">&raquo;</a> </div>
          </div>
        </form>
      </div>
    </div>
    <!-- formList end -->
    <div class="clr"></div>
  </div>
  <%@ include file="inc/footer.inc"%>
  <div id="opacity"></div>
  <div id="editAd" style="display: none">
    <div class="content">
      <div
	style="margin-top: 10px; margin-left: 10px; border-bottom: 1px #000000 dashed; width: 380px; height: 16px;">
        <div id="ad_title" style="width: 300px; left: 0px; float: left"></div>
        <div
	style="float: right; margin-right: 10px; cursor: pointer; font-size: 11px"
	onclick="unlockScreen()">取消<img src="admin/img/reload.gif" /></div>
      </div>
      <div
	style="margin-left: 20px; margin-right: 20px; margin-top: 10px; font-size: 11px;">
        <form action="admin-editAd.htm" method="post">
          <input type="hidden" value="" name="adId" />
          <table style="border-spacing: 6px;">
            <tr>
              <td width="45px">广告名:</td>
              <td><textarea cols="20" style="height: 40px;" name="adName"></textarea></td>
            </tr>
            <tr>
              <td width="45px">链接:</td>
              <td style="margin-left: 10px"><input type="text" name="adHref" value="" style="width:230px;" /></td>
            </tr>
            <tr>
              <td width="45px"></td>
              <td style="margin-left: 10px"><input style="font-size: 11px;"
			id="submit" type="submit" value="提交更改" /></td>
            </tr>
          </table>
        </form>
      </div>
    </div>
  </div>
  <div id="addMultiAds">
    <div class="content">
      <div
	style="margin-top: 10px; margin-left: 10px; border-bottom: 1px #000000 dashed; width: 480px; height: 16px;">
        <div style="width: 400px; left: 0px; float: left"><font
	style="font-weight: bold">添加广告</font></div>
        <div
	style="float: right; margin-right: 10px; cursor: pointer; font-size: 11px"
	onclick="unlockScreen()">取消<img src="admin/img/reload.gif" /></div>
      </div>
      <div
	style="margin-left: 20px; margin-right: 20px; margin-top: 10px; margin-bottom: 20px; font-size: 11px;">
        <form action="admin-adMultiAd.htm" method="post">
          <ul style="margin-left: 30px;" id="ul1">
            <li>
              <table>
                <tr>
                  <td style='width: 170px'><textarea
				style='height: 35px; width: 150px;' name='adNames'>广告名</textarea></td>
                  <td><input type='text' name='adHrefs' value='http://'
				style='width: 250px;' /></td>
                </tr>
              </table>
            </li>
          </ul>
          <ul style="margin-left: 30px;">
            <hr />
            <li>
              <button type="button" value="" style="font-size: 11px; float: right"
		onclick="addRow()">添加一行</button>
              <input type='submit' value='提交' style="font-size: 11px; float: right" />
            </li>
          </ul>
        </form>
      </div>
    </div>
  </div>
</div>
</body>
</html>
